package com.example.test.Dao;


import com.example.test.bean.BraendType;
import com.example.test.mapper.BraendTypeMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.Primary;

import java.util.List;

@Primary
@Mapper
public interface BraendDao extends BraendTypeMapper {

    //根据id查询brandName
    @Select("SELECT\n" +
            "\tbraend_name\n" +
            "FROM\n" +
            "\tbraend_type\n" +
            "WHERE\n" +
            "\tbraend_id = #{braendId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    String getNameById(Long braendId);

    //根据name查询id
    @Select("SELECT\n" +
            "\tbraend_id\n" +
            "FROM\n" +
            "\tbraend_type\n" +
            "WHERE\n" +
            "\tbraend_name = #{braendId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    Long getIdByName(String newBraendName);

    //根据keyword查询
    @Select("SELECT\n" +
            "\tbraend_id,\n" +
            "\tbraend_name\n" +
            "FROM\n" +
            "\tbraend_type\n" +
            "WHERE\n" +
            "\tbraend_name like concat('%',#{keyword},'%')\n" +
            "AND\n" +
            "\tdeleted = 0\n" +
            "LIMIT #{size} OFFSET #{offset}\n")
    List<BraendType> getByKeyword(String keyword, Long size, Long offset);

    //根据id查询
    @Select("SELECT\n" +
            "\tbraend_id,\n" +
            "\tbraend_name\n" +
            "FROM\n" +
            "\tbraend_type\n" +
            "WHERE\n" +
            "\tbraend_id = #{braendId}\n" +
            "AND\n" +
            "\tdeleted = 0\n")
    BraendType getById(Long braendId);


    //分页查询
    @Select("SELECT\n" +
            "\tbraend_id,\n" +
            "\tbraend_name\n" +
            "FROM\n" +
            "\tbraend_type\n" +
            "WHERE\n" +
            "\tdeleted = 0\n" +
            "LIMIT #{size} OFFSET #{offset}\n")
    List<BraendType> getAllBraend(Long size, Long offset);
}
